package com.csair.seam.controller.mobile;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csair.seam.domain.model.entity.Equip;
import com.csair.seam.domain.model.enums.VisitsModule;
import com.csair.seam.domain.service.IEquipService;
import com.csair.seam.infrastructure.log.LogOperation;
import com.csair.seam.infrastructure.log.VisitsLog;
import com.csair.seam.infrastructure.web.BaseController;
import com.csair.seam.infrastructure.web.BaseResponse;
import com.csair.seam.infrastructure.web.ResponseCode;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "设备服务接口")
@RestController
@RequestMapping("/mobile/equip")
public class EquipMobileController extends BaseController {

    @Autowired
    private IEquipService equipService;
    
    @GetMapping("/my")
    @ApiOperation(value = "我的资产", notes = "getMyEquips",httpMethod="GET")
    @LogOperation(bizName = "查询我的资产")
//    @VisitsLog(module = VisitsModule.MY_EQUIP)
    @VisitsLog(module = VisitsModule.MY_EQUIP_QUERY)
    public BaseResponse<List<Equip>> getMyEquips(){
    	return  buildSuccess(equipService.findListByUserCode(getAccountForJwt()));
    }
    
    @GetMapping("/detail/{equipCode}")
    @ApiOperation(value = "‘扫一扫’查询设备信息", notes = "getEquipByCode",httpMethod="GET")
    @LogOperation(bizName = "‘扫一扫’查询设备信息")
    public BaseResponse<Equip> getEquipByCode(@PathVariable @ApiParam(value="设备编码",required = true) String equipCode) {
    	Equip equip = equipService.findEquipByCode(equipCode);
    	if(equip == null) {
    		return new BaseResponse<>(ResponseCode.PARAM_ERROR,"没有该设备",null);
    	}
//    	if(!getAccountForJwt().equals(equip.getUserCode())) {
//    		return new BaseResponse<>(ResponseCode.ERROR,"当前用户无权查看该设备",null);
//    	}
    	return buildSuccess(equip);
    }
}

